﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Text;
using Bpms.Entity;

namespace Bpms.Data
{
    public enum OperateType
    {
        Insert = 1,
        Update
    }

    public delegate void OnDBExceptionEventHandler(object sender, DBExceptionEventArgs e);

    public interface IDataProvider
    {

        void SetLog(Log.LogAdapter log);

        #region User Module

        #region User
        bool InsertUser(UserInfo user);
        bool UpdateUser(UserInfo user);
        bool DeleteUser(int userId);
        bool UserExists(UserInfo user, OperateType type);
        UserInfo GetUser(int userId);
        UserInfo GetUser(string email);
        IList<UserInfo> GetUsers(int pageId, int pageSize, string condition);
        int GetUserCount(string condition);
        bool VerifyUser(ref UserInfo user);
        bool StartUser(int userId);
        bool CancelUser(int userId);
        bool UpdatePassword(int userId, string newPassword);
        bool DistributeCustomer(int userId, string[] customerIdList);
        bool IsContainsCustomer(IList<CustomerInfo> customers, int customerId);
        bool SetRole(int userId, int roleId);
        string GetEmailByUserID(int userId);
        int GetUserIDByEmail(string email);
        #endregion

        #region Organization(Department & Team)
        bool InsertOrganization(OrganizationInfo organization);
        bool UpdateOrganization(OrganizationInfo organization);
        bool DeleteOrganization(int organizationId);
        bool OrganizationExists(OrganizationInfo organization, OperateType type);
        OrganizationInfo GetOrganization(int organizationId);
        IList<OrganizationInfo> GetOrganizations(int pageId, int pageSize, string condition, OrganizationType organizationType);
        IList<OrganizationInfo> GetOrganizations(string condition);
        bool DistributeContact(int organizationId, string[] contactIdList);
        string GetOrganizationName(int organizationId);
        #endregion

        #region Job Title
        bool InsertJobTitle(JobTitleInfo jobTitle);
        bool UpdateJobTitle(JobTitleInfo jobTitle);
        bool DeleteJobTitle(int jobTitleId);
        bool JobTitleExists(JobTitleInfo jobTitle, OperateType type);
        JobTitleInfo GetJobTitle(int jobTitleId);
        IList<JobTitleInfo> GetJobTitles(int pageId, int pageSize, string condition);
        IList<JobTitleInfo> GetJobTitles(string condition);
        string GetJobTitleName(int jobTitleId);
        #endregion

        #region Role
        bool InsertRole(RoleInfo role);
        bool UpdateRole(RoleInfo role);
        bool DeleteRole(int roleId);
        bool RoleExists(RoleInfo role, OperateType type);
        RoleInfo GetRole(int roleId);
        IList<RoleInfo> GetRoles(int pageId, int pageSize, string condition);
        IList<RoleInfo> GetRoles(string condition);
        string GetRoleName(int roleId);
        #endregion
        #endregion



        #region Customer Module

        #region Customer
        bool InsertCustomer(CustomerInfo customer);
        bool UpdateCustomer(CustomerInfo customer);
        bool DeleteCustomer(int customerId);
        bool CustomerExists(CustomerInfo customer, OperateType type);
        CustomerInfo GetCustomer(int customerId);
        IList<CustomerInfo> GetCustomers(int pageId, int pageSize, string condition);
        IList<CustomerInfo> GetCustomers(string condition);

        #endregion


        #region Contact
        bool InsertContact(ContactInfo contact);
        bool UpdateContact(ContactInfo contact);
        bool DeleteContact(int contactId);
        //bool ContactExists(ContactInfo contact, OperateType type);
        ContactInfo GetContact(int contactId);
        IList<ContactInfo> GetContacts(int pageId, int pageSize, string condition);
        IList<ContactInfo> GetContacts(string condition);
        #endregion


        #region Relationship
        bool InsertRelationship(RelationshipInfo relationship);
        bool UpdateRelationship(RelationshipInfo relationship);
        bool DeleteRelationship(int relationshipId);
        bool RelationshipExists(RelationshipInfo relationship, OperateType type);
        RelationshipInfo GetRelationship(int relationshipId);
        IList<RelationshipInfo> GetRelationships(int pageId, int pageSize, string condition);
        #endregion


        #region Area
        bool InsertArea(AreaInfo area);
        bool UpdateArea(AreaInfo area);
        bool DeleteArea(int areaId);
        bool AreaExists(AreaInfo area, OperateType type);
        AreaInfo GetArea(int areaId);
        IList<AreaInfo> GetAreas(int pageId, int pageSize, string condition);
        #endregion


        #region General Job Title
        bool InsertGeneralJobTitle(GeneralJobTitleInfo generalJobTitle);
        bool UpdateGeneralJobTitle(GeneralJobTitleInfo generalJobTitle);
        bool DeleteGeneralJobTitle(int generalJobTitleId);
        bool GeneralJobTitleExists(GeneralJobTitleInfo generalJobTitle, OperateType type);
        GeneralJobTitleInfo GetGeneralJobTitle(int generalJobTitleId);
        IList<GeneralJobTitleInfo> GetGeneralJobTitles(int pageId, int pageSize, string condition);
        #endregion

        #endregion


        #region Project Module

        #region Project

        bool InsertProject(ProjectInfo project);
        bool UpdateProject(ProjectInfo project);
        bool DeleteProject(int projectId);
        bool ProjectExists(ProjectInfo project, OperateType type);
        ProjectInfo GetProject(int projectId);
        IList<ProjectInfo> GetProjects(int pageId, int pageSize, string condition);
        bool CancelProject(int projectId);
        string GenerateProjectNumber(string customerId);
        string GenerateProjectQuotation(string customerId);
        int GetProjectManHour(int orderId);
        #endregion


        #region Order

        //bool InsertOrder(OrderInfo order);
        //bool UpdateOrder(OrderInfo order);
        //bool DeleteOrder(int orderId);
        //bool OrderExists(OrderInfo order, OperateType type);
        //OrderInfo GetOrder(int orderId);
        //IList<OrderInfo> GetOrders(int pageId, int pageSize, string condition);
        //void ChangeOrderStatus(int orderId);
        //string GenerateOrderNumber(string customerId);
        //string GenerateOrderQuotation(string customerId);
        //string GetOrderColor(int orderId);
        //void SendMessage(int orderId);
        //int GetOrderManHour(int orderId);
        //void UpdateProperty(string orderIdString);
        #endregion

        #region Business Category

        bool InsertBusinessCategory(BusinessCategoryInfo businessCategory);
        bool UpdateBusinessCategory(BusinessCategoryInfo businessCategory);
        int IsBusinessCategoryDeleteable(int businessCategoryId);
        bool DeleteBusinessCategory(int businessCategoryId, bool isDeleteRalation);
        bool BusinessCategoryExists(BusinessCategoryInfo businessCategory, OperateType type);
        BusinessCategoryInfo GetBusinessCategory(int businessCategoryId);
        IList<BusinessCategoryInfo> GetAllBusinessCategories();
        IList<BusinessCategoryInfo> GetBusinessCategories(int parentId);
        bool IsBusinessCategorySortable(int businessCategoryId, byte sortNumber);
        bool SetCategorySortNumber(int businessCategoryId, int sortNumber);
        string GetBusinessCategoryNameById(int businessCategoryId);
        int GetBusinessCategoryIdByName(string name);

        #endregion

        #region Business Type

        bool InsertBusinessType(BusinessTypeInfo businessType, BusinessTypeExtensionInfo[] businessTypeExtensions);
        bool UpdateBusinessType(BusinessTypeInfo businessType, BusinessTypeExtensionInfo[] businessTypeExtensions);
        bool DeleteBusinessType(int businessTypeId);
        bool BusinessTypeExists(BusinessTypeInfo businessType, OperateType type);
        BusinessTypeInfo GetBusinessType(int businessTypeId);
        IList<BusinessTypeInfo> GetAllBusinessTypes();
        IList<BusinessTypeInfo> GetBusinessTypes(int businessCategoryId);
        bool IsBusinessTypeSortable(byte sortNumber);
        bool SetTypeSortNumber(int businessTypeId, int sortNumber);

        BusinessTypeExtensionInfo GetBusinessTypeExtension(int businessTypeExtensionId);
        IList<BusinessTypeExtensionInfo> GetAllBusinessTypeExtensions();
        IList<BusinessTypeExtensionInfo> GetBusinessTypeExtensions(int businessTypeId);

        MatchRateInfo GetMatchRate(int matchRateId);
        IList<MatchRateInfo> GetAllMatchRates();

        #endregion

        #region Check Out Way

        bool InsertCheckOutWay(CheckOutWayInfo checkOutWay);
        bool UpdateCheckOutWay(CheckOutWayInfo checkOutWay);
        bool DeleteCheckOutWay(int checkOutWayId);
        bool CheckOutWayExists(CheckOutWayInfo checkOutWay, OperateType type);
        CheckOutWayInfo GetCheckOutWay(int checkOutWayId);
        IList<CheckOutWayInfo> GetCheckOutWays(int pageId, int pageSize, string condition);

        #endregion

        #region  Man Hour

        bool InsertManHourUnit(ManHourUnitInfo manHourUnit);
        bool UpdateManHourUnit(ManHourUnitInfo manHourUnit);
        bool DeleteManHourUnit(int manHourUnitId);
        bool ManHourUnitExists(ManHourUnitInfo manHourUnit, OperateType type);
        ManHourUnitInfo GetManHourUnit(int manHourUnitId);
        IList<ManHourUnitInfo> GetManHourUnits(int pageId, int pageSize, string condition);

        #endregion

        #region  Message

        bool InsertMessage(MessageInfo message);
        bool DeleteMessage(int messageId);
        MessageInfo GetMessage(int messageId);
        IList<MessageInfo> GetMessages(int pageId, int pageSize, string condition);

        #endregion

        #endregion


        #region PO Module

        #region PO
        bool InsertPo(PoInfo po);
        bool UpdatePo(PoInfo po);
        bool DeletePo(int poId);
        bool PoExists(PoInfo po, OperateType type);
        PoInfo GetPo(int poId);
        IList<PoInfo> GetPoes(int pageId, int pageSize, string condition);
        bool CancelPo(int poId);
        bool RecoverPo(int poId);
        #endregion

        #region Currency
        bool InsertCurrency(CurrencyInfo currency);
        bool UpdateCurrency(CurrencyInfo currency);
        bool DeleteCurrency(int currencyId);
        bool CurrencyExists(CurrencyInfo currency, OperateType type);
        CurrencyInfo GetCurrency(int currencyId);
        IList<CurrencyInfo> GetCurrencies(int pageId, int pageSize, string condition);
        #endregion

        #endregion

    }
}
